﻿// Copyright (c) Microsoft Corporation
// All rights reserved

namespace Microsoft.Windows.Controls.Specialized.TextModel
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Text;

    /// <summary>
    /// Describes a line of text.
    /// </summary>
    public class BufferLine
    {
        TextPoint _startPoint;
        int _newLineLength, _length;

        internal BufferLine(TextPoint startPoint, int length, int newLineLength)
        {
            _startPoint = startPoint;
            _length = length;
            _newLineLength = newLineLength;
        }

        /// <summary>
        /// Gets the length of the new line characters.
        /// </summary>
        public int NewLineLength
        {
            get
            {
                return _newLineLength;
            }
        }

        public int Length
        {
            get
            {
                return _length;
            }
        }

        public int LengthIncludingLineBreak
        {
            get
            {
                return Length + _newLineLength;
            }
        }

        public TextPoint StartPoint
        {
            get
            {
                return _startPoint;
            }
        }

        public int End
        {
            get
            {
                return _startPoint + _length;
            }
        }

        public int EndIncludingLineBreak
        {
            get
            {
                return End + _newLineLength;
            }
        }

        public ITextBuffer Buffer
        {
            get
            {
                return _startPoint.TextBuffer;
            }
        }

        public TextSpan TextSpan
        {
            get
            {
                return new TextSpan(_startPoint.TextBuffer, _startPoint.TextBuffer.Version, StartPoint, LengthIncludingLineBreak);
            }
        }
    }
}
